package com.jt.controller;

import com.jt.service.FileService;
import com.jt.vo.ImageVO;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController//标识Controller层，并且返回json串
@CrossOrigin//跨域
@RequestMapping("/file")
public class FileController {

    @Autowired
    private FileService fileService;

    //
    /**
     * 请求路径: http://localhost:8091/file/upload
     * 请求类型: post
     * 请求参数:  file
     * 返回值类型：SysResult(ImageVO)对象
     */
    @PostMapping("/upload")
    public SysResult upload(MultipartFile file){
        ImageVO imageVO = fileService.upload(file);
        if(imageVO == null){
            return SysResult.fail();
        }
        return SysResult.success(imageVO);
    }
    //文件删除业务接口
    /**
     * 请求路径: http://localhost:8091/file/deleteFile
     * 请求类型: delete
     * 请求参数: virtualPath
     * 返回值类型：SysResult(ImageVO)对象
     */
    @DeleteMapping("deleteFile")
    public SysResult deleteFile(String virtualPath){
        fileService.deleteFile(virtualPath);
        return SysResult.success();
    }
}
